package org.skill.panel;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.come.Frame.MsgJframe;
import org.come.Frame.OptionsJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.MsgJapnel;
import org.come.bean.LoginResult;
import org.come.bean.PathPoint;
import org.come.bean.Skill;
import org.come.bean.TYCPointBean;
import org.come.bean.TYCTypeBean;
import org.come.until.*;
import org.skill.btn.SkillTYCBtn;

import com.tool.role.GetExp;
import com.tool.role.RoleData;
import com.tool.role.RoleProperty;
import com.tool.role.SkillUtil;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

import come.tool.JDialog.TiShiUtil;

 

public class CopyOfSkillTYCPanel extends JPanel {
    // 展示剩余技能点数框
    private JLabel maxPointCase;
    private JLabel maxPointLab;
    private SkillTYCBtn switchBtn,// 切换(下拉种族按钮)
            exchangeBtn,// 兑换
            washPointBtn,// 洗点
            simulationBtn,// 模拟加点
            confirmBtn;// 确认加点

    // 种族下拉框
    private JLabel raceCase;// 种族图片
    private JLabel raceLab;// 模拟的种族
    private SkillSMSelectOptionJpanel TYCselect;
    public int typeBtn;

    public CopyOfSkillTYCPanel() {
        if("水墨UI".equals(MyIsif.getStyle())) {
            typeBtn = -1;
            this.setBounds(21, 60, 560, 350);
            this.setOpaque(false);
            this.setLayout(null);

            // String[][] rowData = { { "男人" }, { "女人" }, { "男魔" }, { "女魔" }, { "男仙"
            // }, { "女仙" }, { "男鬼" }, { "女鬼" },
            // { "男龙" }, { "女龙" } };
            String[] rowData = { "男人", "女人", "男魔", "女魔", "男仙", "女仙", "男鬼", "女鬼" };
            TYCselect = new SkillSMSelectOptionJpanel(64, 120, "inkImg/old/background/74.png", rowData);
            TYCselect.setBounds(243, 198, 64, 120);
            this.add(TYCselect);
            // 添加监听
            TYCselect.getJlist().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    // TODO Auto-generated method stub
                    int count = TYCselect.getJlist().getSelectedIndex();// 获取你选中的行号（记录）
                    if (count == -1) {
                        return;
                    }
                    String getname = TYCselect.getJlist().getSelectedValue();// 读取你获取行号的某一列的值（也就是字段）
                    initTYC(getname, null, tycRole.getLvl());
                    raceLab.setText(getname);
                    TYCselect.setVisible(false);
                }
            });

            switchBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_WHITE2, "切换", UIUtils.TEXT_HY16, 0, this);
            this.add(switchBtn);
            exchangeBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_BTNTEXT, "兑换", UIUtils.TEXT_FONT, 1, this);
            this.add(exchangeBtn);
            washPointBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_BTNTEXT, "洗点", UIUtils.TEXT_FONT, 2, this);
            this.add(washPointBtn);
            simulationBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_WHITE2, "模拟加点", UIUtils.TEXT_HY16, 3, this);
            simulationBtn.setBounds(325, 317, 99, 24);
            this.add(simulationBtn);
            confirmBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_WHITE2, "确认加点", UIUtils.TEXT_HY16, 4, this);
            confirmBtn.setBounds(430, 317, 99, 24);
            this.add(confirmBtn);

            maxPointLab = new JLabel();
            maxPointLab.setForeground(Color.white);
            maxPointLab.setBounds(63, 317, 60, 22);
            maxPointLab.setFont(UIUtils.TEXT_FONT1);
            this.add(maxPointLab);
            maxPointCase = new JLabel();
            maxPointCase.setBounds(25, 317, 98, 22);
            maxPointCase.setIcon(CutButtonImage.getImage("inkImg/old/1/72.png", 97, 19));
            this.add(maxPointCase);
            raceLab = new JLabel();
            raceLab.setForeground(Color.white);
            raceLab.setBounds(247, 316, 64, 20);
            raceLab.setFont(UIUtils.TEXT_FONT1);
            this.add(raceLab);
            raceCase = new JLabel();
            raceCase.setBounds(205, 317, 104, 20);
            raceCase.setIcon(CutButtonImage.getImage("inkImg/old/1/73.png", 103, 20));
            this.add(raceCase);

            tycRole = new TYCRole();
            skillTYCs = new MSkillTYC[3];
            for (int i = 0; i < skillTYCs.length; i++) {
                skillTYCs[i] = new MSkillTYC();
                skillTYCs[i].px = 176 * i + 25;
            }
        }else{
            typeBtn = -1;
            this.setBounds(23, 78, 523, 350);
            this.setOpaque(false);
            this.setLayout(null);

            // String[][] rowData = { { "男人" }, { "女人" }, { "男魔" }, { "女魔" }, { "男仙"
            // }, { "女仙" }, { "男鬼" }, { "女鬼" },
            // { "男龙" }, { "女龙" } };
            String[] rowData = { "男人", "女人", "男魔", "女魔", "男仙", "女仙", "男鬼", "女鬼" };
            TYCselect = new SkillSMSelectOptionJpanel(64, 120, "inkImg/hongmu/soaringSkill/下拉框w64,h120px.png", rowData);
            TYCselect.setBounds(218, 202, 64, 120);
            this.add(TYCselect);
            // 添加监听
            TYCselect.getJlist().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    // TODO Auto-generated method stub
                    int count = TYCselect.getJlist().getSelectedIndex();// 获取你选中的行号（记录）
                    if (count == -1) {
                        return;
                    }
                    String getname = TYCselect.getJlist().getSelectedValue();// 读取你获取行号的某一列的值（也就是字段）
                    initTYC(getname, null, tycRole.getLvl());
                    raceLab.setText(getname);
                    TYCselect.setVisible(false);
                }
            });

            switchBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_BTNPUTONG2, "切换", UIUtils.TEXT_HY16, 0, this);
            this.add(switchBtn);
            exchangeBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_BTNTEXT, "兑换", UIUtils.TEXT_FONT, 1, this);
            this.add(exchangeBtn);
            washPointBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_BTNTEXT, "洗点", UIUtils.TEXT_FONT, 2, this);
            this.add(washPointBtn);
            simulationBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_BTNPUTONG2, "模拟加点", UIUtils.TEXT_HY88, 3, this);
            simulationBtn.setBounds(300, 320, 100, 26);
            this.add(simulationBtn);
            confirmBtn = new SkillTYCBtn(null, 1, UIUtils.COLOR_BTNPUTONG2, "确认加点", UIUtils.TEXT_HY88, 4, this);
            confirmBtn.setBounds(410, 320, 100, 26);
            this.add(confirmBtn);

            maxPointLab = new JLabel();
            maxPointLab.setForeground(Color.white);
            maxPointLab.setBounds(58, 320, 60, 22);
            maxPointLab.setFont(UIUtils.TEXT_FONT1);
            this.add(maxPointLab);
            maxPointCase = new JLabel();
            maxPointCase.setBounds(0, 320, 98, 22);
            maxPointCase.setIcon(CutButtonImage.getImage("inkImg/hongmu/soaringSkill/天枢点w98,h22.png", 98, 22));
            this.add(maxPointCase);
            raceLab = new JLabel();
            raceLab.setForeground(Color.white);
            raceLab.setBounds(222, 319, 64, 20);
            raceLab.setFont(UIUtils.TEXT_FONT1);
            this.add(raceLab);
            raceCase = new JLabel();
            raceCase.setBounds(180, 320, 104, 20);
            raceCase.setIcon(CutButtonImage.getImage("inkImg/hongmu/soaringSkill/种族w98,h22.png", 98, 22));
            this.add(raceCase);

            tycRole = new TYCRole();
            skillTYCs = new MSkillTYC[3];
            for (int i = 0; i < skillTYCs.length; i++) {
                skillTYCs[i] = new MSkillTYC();
                skillTYCs[i].px = 176 * i;
            }
        }
    }

    private MSkillTYC[] skillTYCs;
    private TYCRole tycRole;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        g.setFont(UIUtils.TEXT_HY24);
        g.setColor(Color.yellow);
        for (int i = 0; i < skillTYCs.length; i++) {
            skillTYCs[i].draw(g);
        }
    }

    /** 确定加点 */
    public void addPoint() {
        for (int i = 0; i < skillTYCs.length; i++) {
            if (skillTYCs[i].visible) {
                StringBuffer buffer = new StringBuffer();
                buffer.append(skillTYCs[i].value);
                for (int j = 0; j < skillTYCs[i].lists.size(); j++) {
                    XSkillTYC skillTYC = skillTYCs[i].lists.get(j);
                    if (skillTYC.tycPointBean.getNowPoint() <= 0) {
                        continue;
                    }
                    buffer.append("#");
                    buffer.append(skillTYC.tycPointBean.getTableId().toString());
                    buffer.append("_");
                    buffer.append(skillTYC.tycPointBean.getNowPoint());
                }
                String skill = buffer.toString();
                if (skill.equals(skillTYCs[i].value)) {
                    return;
                }
                RoleData.getRoleData().getPrivateData().setSkills("T", skill);
                SendRoleAndRolesummingUntil.sendRole(RoleData.getRoleData().getPrivateData());
                LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                initTYC(SkillUtil.getSepciesN(loginResult.getSpecies_id()), skill.split("#"), loginResult.getGrade());
                ZhuFrame.getZhuJpanel().addPrompt2("已保存");
                RoleProperty.ResetEw();
                break;
            }
        }
    }

    /** 洗点 */
    public void washPoint() {
        if (typeBtn == 1) {
            changeBtnPanel(1);
        } else {// 弹出洗点框
            // tycRole.getDian();
            for (int i = 0; i < skillTYCs.length; i++) {
                if (skillTYCs[i].visible) {
                    int dian = skillTYCs[i].getPoint().getX() * 3000000;
                    if (dian > 0) {
                        OptionsJframe.getOptionsJframe().getOptionsJpanel().
        				showBox(TiShiUtil.washPoint, dian,"#W你确定要花费#R" + dian + "#W银两,重置天演策加点吗?");
                    }
                    break;
                }
            }
        }
    }

    /** 选项按钮点击 0天演策 1是模拟加点 */
    public void changeBtnPanel(int typeBtn) {
        if (this.typeBtn != typeBtn) {
            // 切换按钮
            try {
                changeBtn(typeBtn);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        this.typeBtn = typeBtn;
        // 刷新数据
        String seName = SkillUtil.getSepciesN(RoleData.getRoleData().getLoginResult().getSpecies_id());
        if (this.typeBtn == 0) {
            String[] data = RoleData.getRoleData().getPrivateData().getSkill("T");
            initTYC(seName, data, tycRole.getLvl());
        } else if (this.typeBtn == 1) {
            initTYC(seName, null, tycRole.getLvl());
        }
    }

    /** 根据种族初始化 */
    public void initTYC(String seName, String[] data, int lvl) {
        // SkillUtil.getSepciesN(se);
        tycRole.data = data;
        raceLab.setText(seName);
        maxPointLab.setText(tycRole.getDian() + "");
        String[] vs = SkillUtil.getSepciesS(seName);
        for (int i = 0; i < vs.length; i++) {
            skillTYCs[i].reset(vs[i], data, lvl);
            if (data != null) {
                if (!data[0].equals(skillTYCs[i].value)) {
                    skillTYCs[i].setShow(false);
                }
            }
        }

    }

    /** 切换按钮位置 */
    public void changeBtn(int typeBtn) throws Exception {
        if("水墨UI".equals(MyIsif.getStyle())) {

            if (typeBtn == 0) {
                // 切换 兑换 洗点 位置不变 模拟加点 确定加点
                maxPointCase.setBounds(95, 317, 98, 22);
                maxPointLab.setBounds(153, 317, 60, 22);
                raceCase.setVisible(false);
                raceLab.setVisible(false);
                TYCselect.setVisible(false);

                switchBtn.setBounds(25, 317, 59, 24);
                switchBtn.setText("切换");
                switchBtn.setIcons(CutButtonImage.cuts("skin/8100226/newbutton/B20.png"));

                exchangeBtn.setBounds(195, 318, 34, 17);
                exchangeBtn.setText("兑换");
                exchangeBtn.setIcons(CutButtonImage.cuts("skin/8100226/newbutton/B30.png"));
                exchangeBtn.setBtn(1);

                washPointBtn.setBounds(235, 318, 34, 17);
                washPointBtn.setText("洗点");
                washPointBtn.setIcons(CutButtonImage.cuts("skin/8100226/newbutton/B30.png"));

                simulationBtn.setText("模拟加点");
                simulationBtn.setFont(UIUtils.TEXT_HY16);
                simulationBtn.setIcons(CutButtonImage.cuts("skin/8100226/newbutton/B22.png"));

                confirmBtn.setText("确认加点");
                confirmBtn.setIcons(CutButtonImage.cuts("skin/8100226/newbutton/B22.png"));
                confirmBtn.setBtn(1);
            } else {
                // 下拉按钮 灰兑换 洗点 位置不变 取消模拟 灰确定加点
                maxPointCase.setBounds(25, 317, 98, 22);
                maxPointLab.setBounds(83, 317, 60, 22);
                raceCase.setVisible(true);
                raceLab.setVisible(true);

                switchBtn.setBounds(288, 318, 18, 18);
                switchBtn.setText("");
                switchBtn.setIcons(CutButtonImage.cuts("skin/8100226/button/8.png"));

                exchangeBtn.setBounds(128, 318, 34, 17);
                exchangeBtn.setText("兑换");
                exchangeBtn.setIcon(CutButtonImage.getImage("skin/8100226/newbutton/K136.png", 34, 17));
                exchangeBtn.setBtn(-1);

                washPointBtn.setBounds(165, 318, 34, 17);
                washPointBtn.setText("洗点");
                washPointBtn.setIcons(CutButtonImage.cuts("skin/8100226/newbutton/B30.png"));

                simulationBtn.setText("取消模拟");
                simulationBtn.setIcons(CutButtonImage.cuts("skin/8100226/newbutton/B22.png"));

                confirmBtn.setText("确认加点");
                confirmBtn.setIcon(CutButtonImage.getImage("skin/8100226/newbutton/K153.png", 100, 26));
                confirmBtn.setBtn(-1);
            }
        }else{
            if (typeBtn == 0) {
                // 切换 兑换 洗点 位置不变 模拟加点 确定加点
                maxPointCase.setBounds(95, 317, 98, 22);
                maxPointLab.setBounds(153, 317, 60, 22);
                raceCase.setVisible(false);
                raceLab.setVisible(false);
                TYCselect.setVisible(false);

                switchBtn.setBounds(25, 317, 60, 26);
                switchBtn.setText("切换");
                switchBtn.setIcons(CutButtonImage.cuts("inkImg/hongmu/1/6026.png"));

                exchangeBtn.setBounds(195, 318, 34, 17);
                exchangeBtn.setText("");
                exchangeBtn.setIcons(CutButtonImage.cuts("inkImg/hongmu/soaringSkill/兑换w34,h17.png"));
                exchangeBtn.setBtn(1);

                washPointBtn.setBounds(235, 318, 34, 17);
                washPointBtn.setText("");
                washPointBtn.setIcons(CutButtonImage.cuts("inkImg/hongmu/soaringSkill/洗点w34,h17.png"));

                simulationBtn.setText("模拟加点");
                simulationBtn.setFont(UIUtils.TEXT_HY88);
                simulationBtn.setIcons(CutButtonImage.cuts("inkImg/hongmu/1/1_png.button.btn_xy.png"));

                confirmBtn.setText("确认加点");
                confirmBtn.setIcons(CutButtonImage.cuts("inkImg/hongmu/1/1_png.button.btn_xy.png"));
                confirmBtn.setBtn(1);
            } else {
                // 下拉按钮 灰兑换 洗点 位置不变 取消模拟 灰确定加点
                maxPointCase.setBounds(25, 317, 98, 22);
                maxPointLab.setBounds(83, 317, 60, 22);
                raceCase.setVisible(true);
                raceLab.setVisible(true);

                switchBtn.setBounds(288, 318, 18, 18);
                switchBtn.setText("");
                switchBtn.setIcons(CutButtonImage.cuts("inkImg/hongmu/2/34_png.button.xy_vscroll$down.png"));

                exchangeBtn.setBounds(128, 318, 34, 17);
                exchangeBtn.setText("兑换");
                exchangeBtn.setIcon(CutButtonImage.getImage("inkImg/hongmu/soaringSkill/兑换（黑）w34,h17.png", 34, 17));
                exchangeBtn.setBtn(-1);

                washPointBtn.setBounds(165, 318, 34, 17);
                washPointBtn.setText("洗点");
                washPointBtn.setIcons(CutButtonImage.cuts("inkImg/hongmu/soaringSkill/洗点w34,h17.png"));

                simulationBtn.setText("取消模拟");
                simulationBtn.setIcons(CutButtonImage.cuts("inkImg/hongmu/1/1_png.button.btn_xy.png"));

                confirmBtn.setText("确认加点");
                confirmBtn.setIcon(CutButtonImage.getImage("inkImg/hongmu/1/1_png.button.btn_xy.png", 100, 26));
                confirmBtn.setBtn(-1);
            }
        }

    }

    /** 点数更改 true+ false- */
    public void changePoint(XSkillTYC xSkillTYC, boolean is) {

        if (is) {
            if (xSkillTYC.tycPointBean.getNowPoint() >= xSkillTYC.tycPointBean.getMaxPoint()) {
                return;
            }
        } else {
            if (xSkillTYC.tycPointBean.getNowPoint() <= 0) {
                return;
            }
        }
        MSkillTYC skillTYC = skillTYCs[xSkillTYC.px];
        if (skillTYC == null) {
            return;
        }
        PathPoint point = skillTYC.getPoint();
        if (is) {
            if (tycRole.getDian() <= point.getX()) {
                return;
            }
            if (!skillTYC.isCondition(xSkillTYC, point, tycRole.getLvl(), is)) {
                return;
            }
            xSkillTYC.setPoint(xSkillTYC.tycPointBean.getNowPoint() + 1);
            skillTYC.refreshPanel(tycRole.getLvl());
            for (int i = 0; i < skillTYCs.length; i++) {
                if (skillTYCs[i].visible && skillTYCs[i] != skillTYC) {
                    skillTYCs[i].setShow(false);
                }
            }
            maxPointLab.setText((tycRole.getDian() - point.getX() - 1) + "");
        } else {
            if (typeBtn == 0
                    && tycRole.isDian(xSkillTYC.tycPointBean.getTableId(), xSkillTYC.tycPointBean.getNowPoint())) {
                return;
            }
            xSkillTYC.setPoint(xSkillTYC.tycPointBean.getNowPoint() - 1);
            PathPoint point2 = skillTYC.getPoint();
            for (int i = skillTYC.lists.size() - 1; i >= 0; i--) {
                XSkillTYC xSkillTYC2 = skillTYC.lists.get(i);
                if (xSkillTYC != xSkillTYC2 && (xSkillTYC2.icon1 == null || xSkillTYC2.tycPointBean.getNowPoint() != 0)) {
                    if (!skillTYC.isCondition(xSkillTYC2, point2, tycRole.getLvl(), is)) {
                        xSkillTYC.setPoint(xSkillTYC.tycPointBean.getNowPoint() + 1);
                        return;
                    }
                }
            }
            if (point2.getX() == 0) {
                for (int i = 0; i < skillTYCs.length; i++) {
                    skillTYCs[i].reset(skillTYCs[i].value, null, tycRole.getLvl());
                }
            } else {
                skillTYC.refreshPanel(tycRole.getLvl());
            }
            maxPointLab.setText((tycRole.getDian() - point.getX() + 1) + "");
        }
    }

    /** 天演策技能集合底图 */
    class MSkillTYC {
        private List<XSkillTYC> lists;
        private String value;
        private ImageIcon icon;
        private int px;
        private Integer p;
        public boolean visible;

        /** 重置 */
        public void reset(String value, String[] data, int lvl) {
            this.setShow(true);
            if (this.value == null || !this.value.equals(value)) {
                this.value = value;
                icon = CutButtonImage.TYC(value);
                String[] values = UserMessUntil.getTYC(value).split("\\|");
                if (lists == null) {
                    lists = new ArrayList<>();
                }
                int p = 0;
                int size = lists.size();
                for (int i = 0; i < values.length; i++) {
                    String[] vs = values[i].split("#");
                    TYCPointBean bean = new TYCPointBean();
                    int zhi = Integer.parseInt(vs[0]);
                    bean.setRow(zhi / 10);
                    bean.setRank(zhi % 10);
                    bean.setTableId(Integer.parseInt(vs[1]));
                    Skill skill = UserMessUntil.getSkillId(vs[1]);
                    if (skill != null) {
                        bean.setMaxPoint(Integer.parseInt(skill.getSkilllevel()));
                    } else {
                        bean.setMaxPoint(5);
                    }
                    if (vs.length > 2) {
                        TYCTypeBean tycTypeBean = new TYCTypeBean();
                        for (int j = 2; j < vs.length; j++) {
                            String L = vs[j].substring(1);
                            if (vs[j].startsWith("D")) {// 第一境界 D点数
                                tycTypeBean.setOneTotalPoint(Integer.parseInt(L));
                                continue;
                            }
                            String[] ls = L.split("-");
                            if (vs[j].startsWith("Q")) {// 前置技能 Q技能ID-点数
                                tycTypeBean.setQZID(Integer.parseInt(ls[0]));
                                tycTypeBean.setQZPoint(Integer.parseInt(ls[1]));
                            } else if (vs[j].startsWith("Z")) {// 总点数 Z点数-点数
                                for (int k = 0; k < ls.length; k++) {
                                    tycTypeBean.setTotalPoint(Integer.parseInt(ls[k]));
                                }
                            } else if (vs[j].startsWith("C")) {// 技能互斥
                                                               // C技能ID-技能ID-...
                                for (int k = 0; k < ls.length; k++) {
                                    tycTypeBean.setExclusiveSkill(Integer.parseInt(ls[k]));
                                }
                            } else if (vs[j].startsWith("L")) {// 等级要求 L转-等级
                                tycTypeBean.setLvl(AnalysisString.lvldirection(("4".equals(ls[0]) ? "飞升" : ls[0] + "转")
                                        + ls[1]));
                            }
                        }
                        bean.setTycTypeBean(tycTypeBean);
                    }
                    if (p < size) {
                        lists.get(p).reset(bean, px);
                        p++;
                    } else {
                        p++;
                        XSkillTYC skillTYC = new XSkillTYC(bean, px);
                        lists.add(skillTYC);
                        add(skillTYC);
                    }
                }
                for (int i = size - 1; i >= p; i--) {
                    remove(lists.remove(i));
                }
            } else {
                if (lists == null) {
                    lists = new ArrayList<>();
                }
                for (int i = lists.size() - 1; i >= 0; i--) {
                    lists.get(i).setPoint(0);
                }
            }
            // 法术类型|技能id_点数|技能id_点数|技能id_点数|技能id_点数
            if (data != null && value.equals(data[0])) {
                for (int i = 1; i < data.length; i++) {
                    String[] vs = data[i].split("_");
                    XSkillTYC skillTYC = getTyc(Integer.parseInt(vs[0]));
                    if (skillTYC != null) {
                        skillTYC.setPoint(Integer.parseInt(vs[1]));
                    }
                }
                PathPoint point = getPoint();
                maxPointLab.setText((tycRole.getDian() - point.getX()) + "");
            }
            // 总点数
            // 第一境界 D点数
            // 等级要求
            // 前置技能 Q技能ID-点数
            // 技能互斥 C技能ID-技能ID-...
            refreshPanel(lvl);
        }

        /** 刷新面板 */
        public void refreshPanel(int lvl) {
            if (lists != null) {
                PathPoint point = getPoint();
                for (int i = lists.size() - 1; i >= 0; i--) {
                    XSkillTYC skillTYC = lists.get(i);
                    boolean is = isCondition(skillTYC, point, lvl, true);
                    if (is) {
                        skillTYC.setIcon1(null);
                    } else {
                        skillTYC.setIcon1(CutButtonImage.getImage("inkImg/hongmu/soaringSkill/蒙版w34,h34.png", -1, -1));
                    }
                }
            }
        }

        /** 判断是否符合标准 */
        public boolean isCondition(XSkillTYC skillTYC, PathPoint point, int lvl, boolean type) {
            TYCPointBean bean = skillTYC.tycPointBean;
            TYCTypeBean typeBean = bean.getTycTypeBean();
            if (typeBean == null) {
                return true;
            }
            // 判断前置点数
            Integer dian = typeBean.getQZID();
            if (dian != null && (type ? type : (skillTYC.tycPointBean.getNowPoint() != 0))) {
                XSkillTYC skillTYC2 = getTyc(dian);
                if (skillTYC2 == null) {
                    return false;
                }
                // &&!skillTYC.value.startsWith("0")
                if (typeBean.getQZPoint() > skillTYC2.tycPointBean.getNowPoint()) {
                    return false;
                }
            }
            dian = typeBean.getLvl();
            if (dian != null && dian > lvl) {
                return false;
            }
            dian = typeBean.getOneTotalPoint();
            if (dian != null && dian > point.getY()) {
                return false;
            }
            dian = typeBean.getTotalPoint(bean.getNowPoint());
            if (dian != null && dian > point.getX()) {
                return false;
            }
            List<Integer> list = typeBean.getExclusiveSkills();
            if (list != null) {
                for (int i = 0; i < list.size(); i++) {
                    dian = (int) JmSum.MZ(list.get(i));
                    if (dian.intValue() == bean.getTableId().intValue()) {
                        continue;
                    }
                    XSkillTYC skillTYC2 = getTyc(dian);
                    if (skillTYC2 != null && skillTYC2.tycPointBean.getNowPoint() > 0) {
                        return false;
                    }
                }
            }
            return true;
        }

        /** 根据id查找 */
        public XSkillTYC getTyc(int id) {
            for (int i = lists.size() - 1; i >= 0; i--) {
                if (lists.get(i).tycPointBean.getTableId() == id) {
                    return lists.get(i);
                }
            }
            return null;
        }

        /** 获取总点数和第一境界点数 */
        public PathPoint getPoint() {
            PathPoint point = new PathPoint();
            for (int i = lists.size() - 1; i >= 0; i--) {
                TYCPointBean bean = lists.get(i).tycPointBean;
                point.setX(point.getX() + bean.getNowPoint());
                if (bean.getRow() <= 2) {
                    point.setY(point.getY() + bean.getNowPoint());
                }
            }
            return point;
        }

        public void setShow(boolean flag) {
            visible = flag;
            if (lists != null) {
                for (int i = lists.size() - 1; i >= 0; i--) {
                    lists.get(i).setVisible(visible);
                }
            }
        }

        public void draw(Graphics g) {
            if (visible) {
                g.drawImage(icon.getImage(), px, 0, null);
                if (p == null) {
                    p = g.getFontMetrics().stringWidth(value) / 2;
                    p = px + 85 - p;
                }
                g.drawString(value, p, 28);
            }
        }
    }

    class TYCRole {
        private int lvl = 999;// 模拟的等级
        private int dian = 60;// 点数
        private String[] data;// 学习的数据

        public TYCRole() {
            // TODO Auto-generated constructor stub
            setLvl(999);
            setDian(60);
        }

        public Integer getLvl() {
            if (typeBtn == 0) {
                return RoleData.getRoleData().getLoginResult().getGrade();
            }
            return (int) JmSum.MZ(lvl);
        }

        public void setLvl(Integer lvl) {
            this.lvl = (int) JmSum.ZM(lvl);
        }

        public Integer getDian() {
            if (typeBtn == 0) {
                return GetExp.getTSP(RoleData.getRoleData().getLoginResult().getExtraPointInt("T"));
            }
            return (int) JmSum.MZ(dian);
        }

        public void setDian(Integer dian) {
            this.dian = (int) JmSum.ZM(dian);
        }

        /** 判断最小的点数 */
        public boolean isDian(int id, int dian) {
            if (data == null) {
                return false;
            }
            String ids = id + "";
            for (int i = 1; i < data.length; i++) {
                if (data[i].startsWith(ids)) {
                    return Integer.parseInt(data[i].split("_")[1]) <= dian;
                }
            }
            return false;
        }
    }

    /** 天演策技能 */
    class XSkillTYC extends JComponent implements MouseListener {
        private TYCPointBean tycPointBean;
        // 灰
        private ImageIcon icon1;
        // 技能图标
        private ImageIcon icon2;
        // 数值底框
        private ImageIcon icon3;
        // 数值
        private String value;
        private int py;
        private int px;

        public XSkillTYC(TYCPointBean tycPointBean, int x) {
            // TODO Auto-generated constructor stub
            this.addMouseListener(this);
            reset(tycPointBean, x);
            this.px = x / 176;
        }

        /** 重置 */
        public void reset(TYCPointBean tycPointBean, int x) {
            this.tycPointBean = tycPointBean;
            this.icon1 = null;
            this.icon2 = CutButtonImage.TYCSkill(this.tycPointBean.getTableId());
            setPoint(0);
            this.py = 0;
            this.setBounds(x - 40 + tycPointBean.getRank() * 55, -11 + tycPointBean.getRow() * 46, 38, 38);
        }

        /** 学习进度更改 */
        public void setPoint(int point) {
            value = tycPointBean.setPoint(point);
            if (value.length() == 1) {
                icon3 = CutButtonImage.getImage("inkImg/old/background/S40.png", -1, -1);
            } else {
                icon3 = CutButtonImage.getImage("inkImg/old/background/S39.png", -1, -1);
            }
        }

        /** 根据条件刷新 */
        public void setIcon1(ImageIcon icon1) {
            this.icon1 = icon1;
        }

        @Override
        protected void paintComponent(Graphics g) {
            // TODO Auto-generated method stub
            super.paintComponent(g);
            if (icon2 != null) {
                g.drawImage(icon2.getImage(), py, py, 34, 34, this);
            }
            if (icon3 != null) {
                g.drawImage(icon3.getImage(), 0, 22, this);
            }
            if (value != null) {
                g.setColor(Color.yellow);
                g.setFont(UIUtils.TEXT_FONT);
                g.drawString(value, 3, 33);
            }
            if (icon1 != null) {
                g.drawImage(icon1.getImage(), 0, 0, this);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                if (icon1 != null) {
                    return;
                }
                changePoint(this, true);
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                changePoint(this, false);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (icon1 != null) {
                return;
            }
            py++;
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (icon1 != null) {
                return;
            }
            py--;
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE1)) {
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
            }
            // TODO Auto-generated method stub
            Skill skill = UserMessUntil.getSkillId(tycPointBean.getTableId() + "");
            MsgJframe.getJframe().getJapnel().TYC(skill != null ? skill.getSkillname() : "", getSkillMsg(skill, this));
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE12)) {
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
            }
            // TODO Auto-generated method stub
            FormsManagement.HideForm(46);// 隐藏窗体
        }

    }

    /** 生成技能描述 */
    public String getSkillMsg(Skill skill, XSkillTYC xSkillTYC) {
        TYCPointBean bean = xSkillTYC.tycPointBean;
        TYCTypeBean typeBean = bean.getTycTypeBean();
        int id = bean.getTableId();
        int row = bean.getRow();
        MSkillTYC skillTYC = skillTYCs[xSkillTYC.px];
        if (skillTYC == null || skill == null) {
            return "好像出问题了?联系管理员提交BUG";
        }
        PathPoint point = skillTYC.getPoint();
        StringBuffer buffer = new StringBuffer();
        buffer.append("#cffffff【等级】	");
        buffer.append(bean.getNowPoint());
        buffer.append("/");
        buffer.append(bean.getMaxPoint());
        buffer.append("#r【境界】	");
        buffer.append(row <= 2 ? "1" : row == 3 ? "2" : row <= 5 ? "3" : "4");
        buffer.append("#r【技能类别】	");
        if (id == 9110 || id == 9111 || id == 9126 || id == 9130 || id == 9151 || id == 9169 || id == 9170
                || id == 9171 || id == 9189 || id == 9190 || id == 9207 || id == 9208 || id == 9209 || id == 9231
                || id == 9232 || id == 9250 || id == 9251 || id == 9252 || id == 9262 || id == 9270 || id == 9286
                || id == 9287 || id == 9307 || id == 9350 || id == 9352 || id == 9372 || id == 9389 || id == 9412) {
            buffer.append("主动");
        } else {
            buffer.append("被动");
        }
        String skilllevel = skill.getSkilllevel();
        skill.setSkilllevel(bean.getNowPoint() + "");
        buffer.append(MsgJapnel.skillMsgchange(skill.getRemark(), skill));
        skill.setSkilllevel(skilllevel);
        if (typeBean == null) {
            return buffer.toString();
        }
        boolean is = true;
        Integer dian = typeBean.getLvl();
        if (dian != null && dian > tycRole.getLvl()) {
            if (is) {
                buffer.append("#r#r#cff0000");
                is = false;
            } else {
                buffer.append("#r");
            }
            buffer.append("需要");
            buffer.append(AnalysisString.lvl(dian));
        }
        dian = typeBean.getOneTotalPoint();
        if (dian != null && dian > point.getY()) {
            if (is) {
                buffer.append("#r#r#cff0000");
                is = false;
            } else {
                buffer.append("#r");
            }
            buffer.append("需要第一境界#c00ff00");
            buffer.append(dian);
            buffer.append("#cff0000点");
        }
        dian = typeBean.getTotalPoint(bean.getNowPoint());
        if (dian != null && dian > point.getX()) {
            if (is) {
                buffer.append("#r#r#cff0000");
                is = false;
            } else {
                buffer.append("#r");
            }
            buffer.append("需要总点数#c00ff00");
            buffer.append(dian);
            buffer.append("#cff0000点");
        }
        dian = typeBean.getQZID();
        if (dian != null) {
            XSkillTYC skillTYC2 = skillTYC.getTyc(dian);
            if (skillTYC2 != null && typeBean.getQZPoint() > skillTYC2.tycPointBean.getNowPoint()) {
                Skill skill2 = UserMessUntil.getSkillId(dian.toString());
                if (skill2 != null) {
                    if (is) {
                        buffer.append("#r#r#cff0000");
                        is = false;
                    } else {
                        buffer.append("#r");
                     }
                    buffer.append("需要前置技能#c00ff00");
                    buffer.append(skill2.getSkillname());
                    buffer.append("#cff0000");
                    buffer.append(typeBean.getQZPoint());
                    buffer.append("点数");
                }
            }
        }
        List<Integer> list = typeBean.getExclusiveSkills();
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                dian = (int) JmSum.MZ(list.get(i));
                if (dian.intValue() == bean.getTableId().intValue()) {
                    continue;
                }
                Skill skill2 = UserMessUntil.getSkillId(dian.toString());
                if (skill2 != null) {
                    if (is) {
                        buffer.append("#r#r#cff0000");
                        is = false;
                    } else {
                        buffer.append("#r");
                    }
                    buffer.append("与#c00ff00");
                    buffer.append(skill2.getSkillname());
                    buffer.append("#cff0000技能互斥");
                }
            }
        }
        return buffer.toString();
    }

    public SkillSMSelectOptionJpanel getTYCselect() {
        return TYCselect;
    }

    public void setTYCselect(SkillSMSelectOptionJpanel tYCselect) {
        TYCselect = tYCselect;
    }

}
